<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
import router from "@/router";

const activeKey = ref("");
const changeRouter = (key: string) => {
  activeKey.value = key; // 确保 activeKey 被正确更新
};
watch(
  () => router.currentRoute.value.path,
  (newPath) => {
    if (newPath === "/data") {
      activeKey.value = "1";
      router.push("/printData");
    }
  },
  { immediate: true }
);
watch(activeKey, (newValue, oldValue) => {
  if (newValue === "1") {
    router.push("/printData");
  } else if (newValue === "2") {
    router.push("/afterData");
  }
});
</script>
<template>
  <a-tabs v-model:activeKey="activeKey" @change="changeRouter">
    <a-tab-pane key="1" tab="Table 1" />
    <a-tab-pane key="2" tab="Table 2" />
  </a-tabs>
  <router-view />
</template>

<style scoped></style>
